﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using BlackCoffeeRESTful.Configs;
using BCService.OA.BusinessFlowInstance.BusinessFlowStepInstance;
using BCDto.MySql.BusinessFlowStepInstance;

namespace BlackCoffeeRESTful.Controllers.Management.OA.BusinessFlowStepInstance
{
    /// <summary>
    /// OA系统业务流步骤实例
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class BusinessFlowStepInstanceController : ManagementBaseController
    {
        private readonly IBusinessFlowStepInstanceService businessFlowStepInstanceService;

        public BusinessFlowStepInstanceController(IBusinessFlowStepInstanceService businessFlowStepInstanceService)
        {
            this.businessFlowStepInstanceService = businessFlowStepInstanceService;
        }

        #region 添加OA系统业务流步骤实例
        /// <summary>
        ///  添加OA系统业务流步骤实例
        /// </summary>
        /// <param name="requestDtos">OA系统业务流步骤实例信息列表</param>
        /// <response code="201">添加OA系统业务流步骤实例成功</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加OA系统业务流步骤实例")]
        [ProducesResponseType(typeof(List<BusinessFlowStepInstanceDto>), 200)]
        public IActionResult Post(
            [FromBody]List<BusinessFlowStepInstanceRequestDto> requestDtos)
        {
            var result = this.businessFlowStepInstanceService.Add(requestDtos);
            return this.Ok(result);
        }
        #endregion

        #region 获取OA系统业务流步骤实例
        /// <summary>
        ///  获取OA系统业务流步骤实例
        /// </summary>
        /// <param name="businessFlowStepInstanceId">OA系统业务流步骤实例Id</param>
        /// <response code="200">获取OA系统业务流步骤实例</response>
        /// <returns></returns>
        [HttpGet("{business_flow_step_instance_id}")]
        [ProducesResponseType(typeof(BusinessFlowStepInstanceDto), 200)]
        public IActionResult Get([FromRoute(Name = "business_flow_step_instance_id")]long businessFlowStepInstanceId)
        {
            return this.Ok(this.businessFlowStepInstanceService.GetEntity(businessFlowStepInstanceId));
        }
        #endregion

        #region 获取OA系统业务流步骤实例列表
        /// <summary>
        ///  获取OA系统业务流步骤实例列表
        /// </summary>
        /// <param name="businessFlowInstanceId">业务流实例Id</param>
        /// <response code="200">获取OA系统业务流步骤实例列表</response>
        /// <returns></returns>
        [HttpGet("[action]/{business_flow_instance_id}")]
        [ProducesResponseType(typeof(BusinessFlowStepInstanceDto), 200)]
        public IActionResult List([FromRoute(Name = "business_flow_instance_id")]long businessFlowInstanceId)
        {
            return this.Ok(this.businessFlowStepInstanceService.GetList(businessFlowInstanceId));
        }
        #endregion

        #region 获取OA系统业务流步骤实例（分页）
        /// <summary>
        ///  获取OA系统业务流步骤实例（分页）
        /// </summary>
        /// <param name="businessFlowInstanceId">业务流实例Id</param>
        /// <param name="businessFlowModelId">业务流模型Id</param>
        /// <param name="pageBusinessConfigId">页面业务配置Id</param>
        /// <param name="businessFlowStepInstanceName">OA系统业务流步骤实例名称</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">获取OA系统业务流步骤实例（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<BusinessFlowStepInstanceDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "business_flow_model_id")]long? businessFlowModelId,
            [FromQuery(Name = "business_flow_instance_id")]long? businessFlowInstanceId,
            [FromQuery(Name = "page_business_config_id")]long? pageBusinessConfigId,
            [FromQuery(Name = "business_flow_step_instance_name")]string businessFlowStepInstanceName,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.businessFlowStepInstanceService.Query(businessFlowModelId, businessFlowInstanceId, pageBusinessConfigId, businessFlowStepInstanceName, start, end, pageIndex, pageSize));
        }
        #endregion
    }
}

